#include <stdio.h>
#pragma warning(disable:4786)

#include <string>
#include <map>
#include <config-win.h>
#include <mysql.h>
#include <time.h>

#include "DataBase.h"
#include "Query.h"
#include "IError.h"
#include "ErrorLog.h"

void ErrorLog::error(DataBase &db, const std::string &str)
{
	time_t t = time(NULL);
	struct tm *tp = localtime(&t);
	fprintf(stderr, "%d-%02d-%02d %02d:%02d:%02d :: DataBase: %s\n",
		tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday,
		tp->tm_hour, tp->tm_min, tp->tm_sec,
		str.c_str());
}

void ErrorLog::error(DataBase &db, Query &q, const std::string &str)
{
	time_t t = time(NULL);
	struct tm *tp = localtime(&t);
	fprintf(stderr, "%d-%02d-%02d %02d:%02d:%02d :: Query: %s: %s(%d)\n",
		tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday,
		tp->tm_hour, tp->tm_min, tp->tm_sec, 
		str.c_str(), q.GetError().c_str(), q.GetErrno());
	fprintf(stderr, "(QUERY: \"%s\")\n", q.GetLastQuery().c_str());
}